home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / _CLOSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  546 b   |  27 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <io.h>
  4. main()
  5. {
  6.     char fname[40], *p_fname;
  7.     int filehandle;
  8.     printf("Enter name of file to open using _open: ");
  9.     p_fname = gets(fname);
  10.  
  11. /* Open the file using _open */
  12.     if((filehandle = _open(p_fname, O_RDONLY)) == -1)
  13.     {
  14.         printf("Error opening file:%s\n", fname);
  15.         exit(0);
  16.     }
  17.     printf("File %s opened. \n", fname);
  18.  
  19. /* Now close file */
  20.     if( _close(filehandle) != 0)
  21.     {
  22.         perror("Error closing file with _close");
  23.         exit(0);
  24.     }
  25.     printf("File %s closed.\n", fname);
  26. }
  27.